layui.use(['table','layer','form','jquery'], function(){
    var table = layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.jquery;


    $.post("http://localhost:9527/hallSetMeal/selectSetMeal",{},function (result) {
        var data = result.data;
        var html = "";
        //console.log(result);
        for (var i=0;i<data.length;i++){
            //console.log(data[i]);
            html += '<div class="layui-col-sm6 layui-col-md3" id="getsetmeal">\n' +
                '            <div class="layui-card  layui-bg-green">\n' +
                '                <div class="layui-card-body chart-card">\n' +
                '                    <div class="chart-header">\n' +
                '                        <div class="metawrap">\n' +
                '                            <div class="meta">\n' +
                '                                <span>'+data[i].title+'</span>\n' +
                '                                <span style="display:none" id="getsetmealid">'+data[i].id+'</span>\n' +
                '                            </div>\n' +
                '                            <div class="total">'+data[i].title+'</div>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                    <div class="chart-body">\n' +
                '                        <div class="contentwrap">\n' +
                '                            <span>套餐资费：'+data[i].money+'</span>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                    <div class="chart-footer">\n' +
                '                        <div class="field">\n' +
                '                            <div>流量：'+data[i].flow+'</div>\n' +
                '                            <div>通话时长：'+data[i].conversationtime+'</div>\n' +
                '                            <div>信息条数：'+data[i].message+'</div>\n' +
                '                            <button id="'+data[i].id+'" class="layui-btn layui-btn-radius layui-btn-warm">订购</button>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '            </div>\n' +
                '        </div>';
        }
        $("#setmeal").append(html);
    });


    $(document).on("click","button",function () {
        var setmealid = event.target.id;//套餐id
        var obj = {
            "setmealid":setmealid
        };
        $.post("http://localhost:9527/hallUserPackage/updateUserSetMeal",obj,function (result) {
            var data = result.data;
            //console.log(data)
            if(data==1){
                layer.msg("修改成功");
            }else {
                layer.msg("修改失败");
            }
        })

    })

});